#!/bin/bash

REPO_ROOT="/remote/iosg/jenkins-2/bot-hft/jenkins/workspace/coin2_feed_latency_stats/coin"
# REPO_ROOT="/home/ziyan/workspace/coin"
cd "${REPO_ROOT}"


if [ -n "${1}" ] 
then
  START_TIME="${1}"
else
  BASE_TIME_MINUTE=$(date --utc --date='130 min ago' '+%M')
  BASE_TIME_HOUR=$(date --utc --date='130 min ago' '+%H')
  
  if [[ $BASE_TIME_MINUTE > 30 ]];
  then 
  BASE_TIME_MINUTE='30'
  else
  BASE_TIME_MINUTE='00'
  fi
  
  START_TIME="$(date --utc --date='130 min ago' '+%Y%m%d')T${BASE_TIME_HOUR}${BASE_TIME_MINUTE}"
fi

source /remote/iosg/home/bot-hft/miniconda3/etc/profile.d/conda.sh
conda activate /remote/iosg/home/bot-hft/miniconda3/envs/coin2_motion_env_migration
cd python

./pyrunner coin/support/feed_tool/feed_stats/app/feed_latency_stats/interval_stats_runner_slurm.py \
  --start_time=${START_TIME} \
  --duration="PT30M" \
  --script_only=False \
  --workers=1 \
  --raw = True \
  --interval="5M" \
  --sbatch_args="--wait --hint=nomultithread -n30 --mem-per-cpu=4G --job-name=latencystats --priority=TOP"

conda deactivate
